//
//  HistoryTableViewCell.m
//  jishiben
//
//  Created by 李钰 on 2017/11/27.
//  Copyright © 2017年 jishiben. All rights reserved.
//

#import "HistoryTableViewCell.h"
#import "MyDbTools.h"
@interface HistoryTableViewCell ()
@property (nonatomic,strong)UIImageView * imageMood;
@property (nonatomic,strong)UILabel * labelText;
@property (nonatomic,strong)UILabel * labelDate;
@property (nonatomic,strong)UIView  * shadowView;
@property (nonatomic,strong)UIImageView * wetherIcon;
@end
@implementation HistoryTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle: style reuseIdentifier: reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview: self.shadowView];
        [self.shadowView addSubview: self.imageMood];
        [self.shadowView addSubview: self.labelText];
        [self.shadowView addSubview: self.labelDate];
        [self.shadowView addSubview: self.wetherIcon];
    }
    return self;
}
- (void)setModel:(MoodObj *)model
{
    _model = model;
    self.labelText.text = model.doText;
    self.labelDate.text = [NSString getDateTimeInterval: model.creatTime Format: @"HH:mm" isMS: NO];
    
    NSArray * weatherList = [MyDbTools getWeatherList];
    NSArray * moodList = [MyDbTools getMoodList];
    if (model.mood<moodList.count) {
        self.imageMood.image = [UIImage imageNamed: moodList[model.mood]];
    }
    if (model.weather<weatherList.count) {
        self.wetherIcon.image = [UIImage imageNamed: weatherList[model.weather]];
    }
}
- (UIImageView *)imageMood
{
    if (nil == _imageMood) {
        _imageMood = [[UIImageView alloc] initWithFrame: CGRectMake(15, (self.shadowView.height-46)/2, 46, 46)];
        _imageMood.layer.cornerRadius = _imageMood.height/2;
        _imageMood.layer.masksToBounds = YES;
    }
    return _imageMood;
}
- (UILabel *)labelText
{
    if (nil == _labelText) {
        _labelText = [[UILabel alloc] initWithFrame: CGRectMake(self.imageMood.right+10, 5, self.shadowView.width-65-(self.imageMood.right+10), 60)];
        _labelText.font = [UIFont systemFontOfSize: 16];
        _labelText.numberOfLines = 3;
    }
    return _labelText;
}
- (UILabel *)labelDate
{
    if (nil == _labelDate) {
        _labelDate = [[UILabel alloc] initWithFrame: CGRectMake(self.shadowView.width-80, 40, 65, 20)];
        _labelDate.font = [UIFont systemFontOfSize: 14.f];
        _labelDate.textAlignment = NSTextAlignmentRight;
        _labelDate.textColor = RGBA(0, 0, 0, 0.6);
    }
    return _labelDate;
}
- (UIView *)shadowView
{
    if (nil == _shadowView) {
        _shadowView = [[UIView alloc] initWithFrame: CGRectMake(15, 0, ScreenWidth-30, 70)];
        _shadowView.layer.cornerRadius = 5.f;
        _shadowView.backgroundColor = [UIColor whiteColor];
    }
    return _shadowView;
}
- (UIImageView *)wetherIcon
{
    if (nil == _wetherIcon) {
        _wetherIcon = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"sun_Image"]];
        _wetherIcon.left = self.shadowView.width-15-_wetherIcon.width;
        _wetherIcon.top = 15;
    }
    return _wetherIcon;
}
@end
